<?php
namespace app\app\model;
use think\Db;
use think\Model;

class BlockModel extends Model{

    public $user_id;
    protected $table = "a_block";

    /**
     * 获取闯关信息
     */
    public function getInfo(){
        return $this->where('user_id','eq',$this->user_id)->find();
    }

    /**
     * 保存闯关层数
     * @param array $number
     * @return false|int|void
     */
    public function saveNumber($number){
        $block = $this->where('user_id','eq',$this->user_id)->find();
        $this->update(array('id'=>$block['id'],'num'=>$number));
        return true;
    }

    /**
     * 获取用户信息及闯关
     * @param $id
     */
    public function getOne($id){
        $user = Db::name('users')->alias('a')->field('a.id,a.nickname,a.avatar_url,b.num')->join('block b','b.user_id=a.id','left')->where('a.id','eq',$id)->find();
        return $user;
    }


    /**
     * 获取称号
     */
    public function getAchieve(){
        $achieve = Db::name('user_achieve')->alias('a')->join('achieve b','a.achieve_id=b.id','left')
            ->field('b.name,b.img')->where('a.user_id','eq',$this->user_id)->find();
        if($achieve == null) return '';
        return $achieve;
    }
}